package com.neutech.neupha.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.neutech.neupha.service.DrugsService;
import com.neutech.neupha.vo.DrugsVo;
import com.neutech.neupha.vo.ToAddDrugsVo;

@RestController
@RequestMapping("/neupha/drugs")
public class DrugsController {
	@Autowired
	private DrugsService drugsService;
	
	@RequestMapping(value="/queryAllDrugs",method=RequestMethod.GET)
	public List<DrugsVo> queryAllDrugs(){
		return drugsService.queryAllDrugs();
	}
	
	@RequestMapping(value="/queryDrugs",method=RequestMethod.GET)
	public List<DrugsVo> queryDrugs(String name){
		return drugsService.queryDrugs(name);
	}
	
	@RequestMapping(value="/addDrugs",method=RequestMethod.POST)
	public String addDrugs(@RequestBody DrugsVo drugs){
		int result = drugsService.addDrugs(drugs);
		if(result==1){
			return "success";
		}else{
			return "error";
		}
	}
	@RequestMapping(value="/toAddDrugs",method=RequestMethod.GET)
	public ToAddDrugsVo toAddDrugs(){
		return drugsService.toAddDrugs();
	}	
	@RequestMapping(value="/updateDrugs",method=RequestMethod.POST)
	public String updateDrugs(@RequestBody DrugsVo drugs){
		int result = drugsService.updateDrugs(drugs);
		if(result==1){
			return "success";
		}else{
			return "error";
		}
	}
	@RequestMapping(value="/toUpdateDrugs",method=RequestMethod.GET)
	public ToAddDrugsVo toUpdateDrugs(){
		return drugsService.toAddDrugs();
	}	
	@RequestMapping(value="/delDrugs",method=RequestMethod.GET)
	public String delDrugs(@RequestParam int id){
		int result = drugsService.delDrugs(id);
		if(result==1){
			return "success";
		}else{
			return "error";
		}
	}
}
